package com.hygj.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.hygj.baseUtil.BaseDao;
import com.hygj.baseUtil.BaseServiceImpl;
import com.hygj.pojo.Role;
import com.hygj.pojo.UserRole;
import com.hygj.service.UserRoleService;

@Service("userRoleService")
public class UserRoleServiceImpl extends BaseServiceImpl<UserRole> implements UserRoleService{
	
	
	
	@Resource(name = "userRoleDao")
	@Override
	public void setDao(BaseDao<UserRole> dao) {
		// TODO Auto-generated method stub
		super.setDao(dao);
	}

	@Override
	public List<Role> listRoles(int uid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", uid);
		
		List<UserRole> userRoles = this.listAll("getRoles", params);
		List<Role> roles = new ArrayList<Role>();
		if(CollectionUtils.isNotEmpty(userRoles) ){
			for(UserRole userRole: userRoles){
				roles.addAll(userRole.getRoles());
			}
		}
		
		return roles;
		
	}
}
